package de.htw.praxisprojekt.data.draw;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;

import de.htw.praxisprojekt.Vector2D;

public class DrawLine extends DrawObject{

	private Vector2D p1=new Vector2D();
	private Vector2D p2=new Vector2D();
	private float dash1[]={10.0f};
	private BasicStroke dashed=new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0f,dash1,0.0f);

	private boolean isDashed=false;

	private float lineWidth=1;

	public DrawLine(Vector2D p1,Vector2D p2){
		this.p1.set(p1);
		this.p2.set(p2);
	}

	public DrawLine setDashed(boolean isDashed){
		this.isDashed=isDashed;
		return this;
	}

	public void setLineWidth(float lineWidth){
		this.lineWidth=lineWidth;
	}

	@Override
	public void draw(Graphics2D g2d){
		g2d.setColor(color);
		Stroke defaultStroke=g2d.getStroke();
		if(isDashed)
			g2d.setStroke(dashed);
		else
			g2d.setStroke(new BasicStroke(lineWidth));
		int height=g2d.getClipBounds().height;
		g2d.drawLine(p1.getX(),height-p1.getY(),p2.getX(),height-p2.getY());
		g2d.setStroke(defaultStroke);
	}
}